<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\Request;

/**
 * 首页接口
 */
class Other extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    protected $beforeActionList = [
        'first'
    ];

    public function first()
    {
        /*$request = Request::instance();
        $param_array = $request->param();

        $m_userhome = DB::name("userhome");
        #查询用户信息，控制用户单点登录
        if(empty($_SERVER['HTTP_TOKEN'])){
            $token = '';
        }else{
            $token = $_SERVER['HTTP_TOKEN'];
        }

        $user_map['id'] = $param_array['uid'];
        $user_data = $m_userhome->where($user_map)->find();
        $user_token = $user_data['token'];

        if($token != $user_token or empty($param_array['uid']) or empty($token)){
            if(empty($param_array['token'])){
                $param_array['token'] = '';
            }
            
            if($param_array['token'] != '666'){
                #$this->error('登录状态异常','',1);
            }
        }
*/
    }


    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }


    /*
    * 购物券金额
    */
    public function vouchers_number()
    {
        $m_userhome = Db::name("userhome");

        $request = Request::instance();

        $uid = $request->param("uid");
        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        $map['id'] = $uid;
        $data = $m_userhome->field("vouchers")->where($map)->find();

        $this->success("成功", $data['vouchers'], '200');
    }

    /*
    * 购物券列表  明细
    */
    public function vouchers_detail()
    {
        $m_vouchers = Db::name("vouchers");
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $type = $request->param("type") ? $request->param("type") : 0;
        $page = $request->param("page") ? $request->param("page") : 1;
        $page_count = $request->param("page_count") ? $request->param("page_count") : 10;

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        if (!empty($type)) {
            $map['type'] = array("in", '3,4');
        }
        $map['userhome_id'] = $uid;
        $list = $m_vouchers->field("id,bean_num,type,createtime,user_id")->where($map)->order("id desc")->page($page, $page_count)->select();
        foreach ($list as $i => $v) {
            $list[$i]['createtime'] = date("Y.m.d H:i:s", $list[$i]['createtime']);
            $list[$i]['phone'] = '';
            if (!empty($list[$i]['user_id'])) {
                $u_map['id'] = $list[$i]['user_id'];
                $u_data = $m_userhome->field("phone")->where($u_map)->find();
                $list[$i]['phone'] = $u_data['phone'];
            }
        }

        $this->success("成功", $list, '200');
    }


    /*
    * 我的邀请
    */
    public function earnings_data()
    {
        $m_vouchers = Db::name("vouchers");
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $new_login = new Login();
        $user_map['id'] = $uid;
        $user_data = $m_userhome->field("avatar")->where($user_map)->find();

        $echo_data['avatar'] = $new_login->image_url($user_data['avatar']);
        #累计收益
        $map['type'] = 5;
        $map['userhome_id'] = $uid;
        $echo_data['bean_num'] = $m_vouchers->where($map)->sum("bean_num");

        #下线总消费
        $map1['pid'] = $uid;
        $echo_data['money'] = $m_userhome->where($map1)->sum("spend");

        #邀请总人数
        $map2['pid'] = $uid;
        $echo_data['count'] = $m_userhome->where($map1)->count();

        $this->success("成功", $echo_data, '200');
    }


    /*
    * 我的邀请，收益明细
    */
    public function earnings_detail()
    {
        $m_vouchers = Db::name("vouchers");
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $page = $request->param("page") ? $request->param("page") : 1;
        $page_count = $request->param("page_count") ? $request->param("page_count") : 10;

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $new_login = new Login();

        $map['type'] = 5;
        $map['userhome_id'] = $uid;
        $list = $m_vouchers->field("id,bean_num,createtime,user_id")->where($map)->order('id desc')->page($page, $page_count)->select();
        foreach ($list as $i => $v) {
            $list[$i]['createtime'] = date("Y.m.d H:i:s", $list[$i]['createtime']);
            $user_map['id'] = $list[$i]['user_id'];
            $user_data = $m_userhome->field("nickname,avatar")->where($user_map)->find();

            $list[$i]['nickname'] = $user_data['nickname'];
            $list[$i]['avatar'] = $new_login->image_url($user_data['avatar']);
        }

        $this->success("成功", $list, '200');
    }

    /*
    * 全部邀请
    */
    public function all_invite()
    {
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $page = $request->param("page") ? $request->param("page") : 1;
        $page_count = $request->param("page_count") ? $request->param("page_count") : 10;

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $new_login = new Login();

        $map['pid'] = $uid;
        $list = $m_userhome->field("nickname,avatar,createtime,spend")->where($map)->order('id desc')->page($page, $page_count)->select();
        $new_login = new Login();
        foreach ($list as $i => $v) {
            $list[$i]['createtime'] = date("Y.m.d", $list[$i]['createtime']);
            $list[$i]['avatar'] = $new_login->image_url($list[$i]['avatar']);
        }

        $this->success("成功", $list, '200');
    }

    /*
    * 转赠 判断
    */
    public function giving_judge()
    {
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $phone = $request->param("phone");
        $number = $request->param("number");

        if (empty($uid)) {
            $this->error("请登录");
        }
        if (empty($phone)) {
            $this->error("手机号不能为空");
        }
        if (empty($number)) {
            $this->error("金额不能为0");
        }

        #查询用户资料
        $user_map['id'] = $uid;
        $user_data = $m_userhome->field("vouchers,zfpwd")->where($user_map)->find();
        if (empty($user_data)) {
            $this->error("请登录");
        }

        if (empty($user_data['zfpwd'])) {
            $this->error("请设置支付密码", '', '202');
        }

        if ($user_data['vouchers'] < $number) {
            $this->error("余额不足", '', '201');
        }

        #查询赠送手机号是否存在
        $map['phone'] = $phone;
        $map['id'] = array("neq", $uid);
        $data = $m_userhome->where($map)->find();

        if (empty($data)) {
            $this->error("用户不存在");
        }

        $this->success("成功", '', '200');
    }

    /*
    * 转赠与
    */
    public function giving_perform()
    {
        $m_userhome = Db::name("userhome");
        $m_vouchers = Db::name("vouchers");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $phone = $request->param("phone");
        $number = $request->param("number");
        $pwd = $request->param("pwd");

        if (empty($uid)) {
            $this->error("请登录");
        }
        if (empty($phone)) {
            $this->error("手机号不能为空");
        }
        if (empty($number)) {
            $this->error("金额不能为0");
        }

        #查询用户资料
        $user_map['id'] = $uid;
        $user_data = $m_userhome->field("vouchers,zfpwd")->where($user_map)->find();
        if (empty($user_data)) {
            $this->error("请登录");
        }

        if (empty($user_data['zfpwd'])) {
            $this->error("请设置支付密码", '', '202');
        }

        if ($user_data['vouchers'] < $number) {
            $this->error("余额不足", '', '201');
        }

        #查询赠送手机号是否存在
        $map['phone'] = $phone;
        $map['id'] = array("neq", $uid);
        $data = $m_userhome->where($map)->find();

        if (empty($data)) {
            $this->error("用户不存在");
        }

        #判断密码
        if ($user_data['zfpwd'] != md5($pwd)) {
            $this->error("支付密码错误");
        }

        #赠送人减少
        $m_userhome->where($user_map)->setDec("vouchers", $number);

        #接收人增加
        $u_map['id'] = $data['id'];
        $m_userhome->where($u_map)->setInc("vouchers", $number);

        #明细
        $vouchers_data['userhome_id'] = $uid;
        $vouchers_data['bean_num'] = $number;
        $vouchers_data['type'] = 3;
        $vouchers_data['user_id'] = $data['id'];
        $vouchers_data['createtime'] = time();
        $m_vouchers->insertGetId($vouchers_data);

        $vouchers_data['userhome_id'] = $data['id'];;
        $vouchers_data['type'] = 4;
        $vouchers_data['user_id'] = $uid;
        $m_vouchers->insertGetId($vouchers_data);

        $user_update['end_xf_time'] = time();
        $m_userhome->where($user_map)->update($user_update);
        $user_update1['end_rz_time'] = time();
        $m_userhome->where($u_map)->update($user_update1);
        $this->success("成功", '', '200');
    }

    /*
    * 设置交易密码
    */
    public function set_pwd()
    {
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $zfpwd = $request->param("zfpwd");
        $phone = $request->param("phone");

        if (empty($uid)) {
            $this->error("请登录");
        }

        if (empty($zfpwd)) {
            $this->error("密码不能为空");
        }

        #验证验证码
        $new_login = new Login();
        $new_login->if_code();

        $map['id'] = $uid;
        $data['zfpwd'] = md5($zfpwd);
        $m_userhome->where($map)->update($data);

        $this->success("成功", '', '200');
    }

    /*
    * 芸豆列表
    */
    public function bean_list()
    {
        $m_beanlist = Db::name("beanlist");
        $m_beanset = Db::name("beanset");

        #芸豆列表
        $list = $m_beanlist->field("name")->order("name asc")->select();

        #比例
        $set_data = $m_beanset->field("bean_number,vouchers_number")->find();

        $data['list'] = $list;
        $data['set_data'] = $set_data;
        $this->success("成功", $data, '200');
    }

    /*
    * 购物券金额
    */
    public function bean_number()
    {
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $map['id'] = $uid;
        $data = $m_userhome->field("bean,use_integral,add_integral")->where($map)->find();

        $this->success("成功", $data, '200');
    }

    /*
    * 购物券兑换芸豆
    */
    public function bean_exchange()
    {
        $m_userhome = Db::name("userhome");
        $m_beanset = Db::name("beanset");
        $m_vouchers = Db::name("vouchers");
        $m_bean = Db::name("bean");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $number = $request->param("number");    #要兑换得芸豆数量

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }
        if (empty($number)) {
            $this->error("芸豆不能为0", '', '201');
        }

        $user_map['id'] = $uid;
        $user_data = $m_userhome->field("vouchers")->where($user_map)->find();

        #计算比例
        $set_data = $m_beanset->field("bean_number,vouchers_number")->find();
        $ratio = bcdiv($set_data['bean_number'], $set_data['vouchers_number'], 2);

        #计算所需券得金额
        $vouchers_number = bcdiv($number, $ratio, 2);

        #判断券余额
        if ($user_data['vouchers'] < $vouchers_number) {
            $this->error("券余额不足");
        }

        $m_userhome->where($user_map)->setInc("bean", $number);   #增加芸豆
        $m_userhome->where($user_map)->setDec("vouchers", $vouchers_number);   #减少券

        #增加券明细
        $mingxi1_data['userhome_id'] = $uid;
        $mingxi1_data['bean_num'] = $vouchers_number;
        $mingxi1_data['type'] = 6;
        $mingxi1_data['user_id'] = 0;
        $mingxi1_data['createtime'] = time();
        $m_vouchers->insertGetId($mingxi1_data);
        #增加芸豆明细
        $mingxi2_data['userhome_id'] = $uid;
        $mingxi2_data['bean_num'] = $number;
        $mingxi2_data['type'] = 2;
        $mingxi2_data['createtime'] = time();
        $mingxi2_data['signnum'] = 0;
        $mingxi2_data['signdate'] = '';
        $m_bean->insertGetId($mingxi2_data);

        $user_update['end_xf_time'] = time();
        $m_userhome->where($user_map)->update($user_update);

        $this->success("成功", "", '200');
    }


    /*
    * 芸豆兑换购物券
    */
    public function vouchers_exchange()
    {
        $m_userhome = Db::name("userhome");
        $m_beanset = Db::name("beanset");
        $m_vouchers = Db::name("vouchers");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        // if ($res == 0) {
        //     $this->error('账号异常','',206);
        // }
        // if ($res == 1) {
        //     $this->error('非法的请求','',201);
        // }
        $number = $request->param("number");    #要兑换得券金额

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }
        if (empty($number)) {
            $this->error("券不能为0", '', '201');
        }
        try {
            Db::startTrans();
            $user_map['id'] = $uid;
            $user_data = Db::name("userhome")->where(['id' => $uid])->lock(true)->find();

            #计算比例
            $set_data = $m_beanset->field("bean_number,vouchers_number,integral")->find();
            $ratio = bcdiv($set_data['integral'], $set_data['vouchers_number'], 2);

            #计算所需积分得数量
            $vouchers_number = bcmul($number, $ratio, 2);
            // $vouchers_number = $number;
            #判断券余额
            // dump($ratio);die;
            #判断积分数量满足否
            if (intval(strval($user_data['use_integral'] * 100)) < intval(strval($vouchers_number * 100))) {
                $this->error("积分余额不足");
            }
            $m_userhome->where($user_map)->setDec("use_integral", $vouchers_number);   #减少积分
            $m_userhome->where($user_map)->setInc("vouchers", $number);   #增加券

            #增加券明细
            $mingxi1_data['userhome_id'] = $uid;
            $mingxi1_data['bean_num'] = $number;
            $mingxi1_data['type'] = 11;
            $mingxi1_data['user_id'] = 0;
            $mingxi1_data['createtime'] = time();
            $m_vouchers->insertGetId($mingxi1_data);
            #增加积分明细
            $incomeScoreLog = [
                'userId' => $uid,
                'score' => $vouchers_number,
                'grandScore' => $user_data['add_integral'],
                'consumeScore' => (intval(strval($user_data['use_integral'] * 100)) - intval(strval($vouchers_number * 100))) / 100,
                'source' => "CONPOUT",
                'createTime' => date("Y-m-d H:i:s"),//下单时间
                'status' => "ENTER",
                'break' => "使用了积分兑换了消费券"
            ];
            DB::name('user_income_score_log')->insertGetId($incomeScoreLog);
            $user_update['end_rz_time'] = time();
            $m_userhome->where($user_map)->update($user_update);
            Db::commit();
        } catch (ValidateException $e) {
            Db::rollback();
            $this->error($e->getMessage());
        } catch (PDOException $e) {
            Db::rollback();
            $this->error($e->getMessage());
        } catch (Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        $this->success("成功", "", '200');
    }


    /*
    * 购物券列表
    */
    public function vouchers_list()
    {
        $m_userhome = Db::name("userhome");
        $m_voucherslist = Db::name("voucherslist");
        $m_beanset = Db::name("beanset");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        if (empty($uid)) {
            $this->error("请登录");
        }

        #个人资料
        $user_map['id'] = $uid;
        $user_data = $m_userhome->field("bean,use_integral")->where($user_map)->find();

        #芸豆列表
        $list = $m_voucherslist->field("name")->order("name asc")->select();

        #比例
        $set_data = $m_beanset->field("bean_number,vouchers_number,integral")->find();
        $ratio = bcdiv($set_data['bean_number'], $set_data['vouchers_number'], 2);
        $integralRatio = bcdiv($set_data['integral'], $set_data['vouchers_number'], 2);

        foreach ($list as $i => $v) {
            #计算所需芸豆得数量
            $number = bcmul($list[$i]['name'], $ratio, 0);
            $list[$i]['number'] = $number;
            #判断芸豆数量满足否
            $list[$i]['status'] = 0;
            if ($user_data['bean'] < $number) {
                $list[$i]['status'] = 1;
            }
            #计算积分数量
            $number = bcmul($list[$i]['name'], $integralRatio, 0);
            $list[$i]['integral'] = $number;
            #判断积分数量满足否
            $list[$i]['integralStatus'] = 0;
            if (intval(strval($user_data['use_integral'])) < $number) {
                $list[$i]['integralStatus'] = 1;
            }
        }

        $this->success("成功", $list, '200');
    }

    /*
    * 芸豆明细
    */
    public function bean_detail()
    {
        $m_bean = Db::name("bean");
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $page = $request->param("page") ? $request->param("page") : 1;
        $page_count = $request->param("page_count") ? $request->param("page_count") : 10;

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $map['userhome_id'] = $uid;
        $list = $m_bean->field("id,bean_num,type,createtime")->where($map)->order("id desc")->page($page, $page_count)->select();
        foreach ($list as $i => $v) {
            $list[$i]['createtime'] = date("Y.m.d H:i:s", $list[$i]['createtime']);

        }

        $this->success("成功", $list, '200');
    }

    /*
    * 签到
    */
    public function sign_list()
    {
        $m_bean = Db::name("bean");
        $m_sign_rule = Db::name("sign_rule");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $today = date("Y-m-d", time());
        $yesterday = date("Y-m-d", time() - 86400);
        #$today = '2021-09-25';   #今天时间
        #$yesterday = '2021-09-24';  #昨天时间

        #查询最后一次签到
        $map['userhome_id'] = $uid;
        $map['type'] = '1';
        $data = $m_bean->where($map)->field("signnum,signdate")->order("id desc")->find();

        if (empty($data)) {
            $echo_data['signnum'] = 0;
            $echo_data['today'] = 0;
        } else {
            if ($data['signdate'] == $today) {
                #今天已签到
                $echo_data['signnum'] = $data['signnum'];
                $echo_data['today'] = 1;
            } elseif ($data['signdate'] == $yesterday) {
                #今天未签到，昨天已签到
                $echo_data['signnum'] = $data['signnum'];
                $echo_data['today'] = 0;
            } else {
                #今天未签到，未连续签到
                $echo_data['signnum'] = 0;
                $echo_data['today'] = 0;
            }
        }

        #查询签到规则
        $sifn_list = $m_sign_rule->field("name,number")->order("name asc")->select();

        #处理是否签到
        foreach ($sifn_list as $i => $v) {
            $number = $i + 1;
            $sifn_list[$i]['today'] = 0;
            $sifn_list[$i]['if_sign'] = 0;
            if ($number <= $echo_data['signnum']) {
                $sifn_list[$i]['if_sign'] = 1;
            }
        }

        #处理今天
        $if_today = 0;
        if ($echo_data['today'] == 1) {
            $echo_data['signnum'] = $echo_data['signnum'] - 1;
        }
        $sifn_list[$echo_data['signnum']]['today'] = 1;

        #如果今天已签到，则天数+1
        if (!empty($echo_data['today'])) {
            $echo_data['signnum']++;
        }
        $echo_data['list'] = $sifn_list;
        if (isset($echo_data['list'][7])) {
            unset($echo_data['list'][7]);
            $echo_data['list'][6]['today'] = 1;
            # code...
        }
        // dump($echo_data);die;
        $this->success("成功", $echo_data, '200');
    }

    /*
    * 签到   七天制  
    */
    public function sign_data()
    {
        $m_bean = Db::name("bean");
        $m_sign_rule = Db::name("sign_rule");
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $today = date("Y-m-d", time());   #今天时间
        $yesterday = date("Y-m-d", time() - 86400);  #昨天时间
        #$today = '2021-09-25';   #今天时间
        #$yesterday = '2021-09-24';  #昨天时间

        #查询最后一次签到
        $map['userhome_id'] = $uid;
        $map['type'] = '1';
        $data = $m_bean->where($map)->field("signnum,signdate")->order("id desc")->find();

        $signnum = 0;   #连续签到天数
        if (!empty($data)) {
            if ($data['signdate'] == $today) {
                #今天已签到
                $this->error("今日已签到");
            } elseif ($data['signdate'] == $yesterday) {
                #今天未签到，昨天已签到
                $signnum = $data['signnum'];
            } else {
                #第一次未签到
                $signnum = 0;
            }
        }

        #第 $signnum + 1 天签到
        if ($signnum >= 7) {
            $signnum = 0;
        }

        $signnum++;  #第几天签到

        #签到奖励
        $sign_map['name'] = $signnum;
        $sign_data = $m_sign_rule->where($sign_map)->find();

        if (empty($sign_data)) {
            $this->error("发生错误，请稍后");
        }

        #给用户增加奖励
        $user_map['id'] = $uid;
        $m_userhome->where($user_map)->setInc("use_integral", $sign_data['number']);
        $m_userhome->where($user_map)->setInc("add_integral", $sign_data['number']);

        $user_data = Db::name("userhome")->where(['id' => $uid])->find();
        $incomeScoreLog = [
            'userId' => $uid,
            'score' => $sign_data['number'],
            'grandScore' => $user_data['add_integral'],
            'consumeScore' => $user_data['use_integral'],
            'source' => "SIGN",
            'createTime' => date("Y-m-d H:i:s"),//下单时间
            'status' => "ENTER",
            'break' => "签到"
        ];
        DB::name('user_income_score_log')->insertGetId($incomeScoreLog);
        #明细以及签到执行
        $bean_data['userhome_id'] = $uid;
        $bean_data['bean_num'] = $sign_data['number'];
        $bean_data['type'] = '1';
        $bean_data['createtime'] = time();
        $bean_data['signnum'] = $signnum;
        $bean_data['signdate'] = $today;
        $m_bean->insertGetId($bean_data);

        $this->success("成功", '', '200');
    }

    /*
    * 新人优惠券
    */
    public function new_coupons()
    {
        $m_coupons = Db::name("coupons");
        $m_couponsuser = Db::name("couponsuser");
        $m_goods_one_type = Db::name("goods_one_type");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $list = $m_coupons->field("id,goods_one_type_id,money,name,number")->order("weigh desc")->select();
        foreach ($list as $i => $v) {
            $list[$i]['user_get'] = '0';
            #判断是否领取
            $if_map['coupons_id'] = $list[$i]['id'];
            $if_map['type'] = '1';
            $if_map['userhome_id'] = $uid;
            $if_data = $m_couponsuser->where($if_map)->find();
            if (!empty($if_data)) {
                $list[$i]['user_get'] = '1';
            }

            if (!empty($list[$i]['goods_one_type_id'])) {
                $type_map['id'] = $list[$i]['goods_one_type_id'];
                $type_data = $m_goods_one_type->where($type_map)->find();
                $list[$i]['type_name'] = $type_data['name'];
            } else {
                $list[$i]['type_name'] = '全品类';
            }
        }

        $this->success("成功", $list, '200');
    }


    /*
    * 领取新人优惠券
    */
    public function receive_coupons()
    {
        $m_coupons = Db::name("coupons");
        $m_couponsuser = Db::name("couponsuser");
        $m_goods_one_type = Db::name("goods_one_type");
        $m_order = Db::name("order");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $coupons_id = $request->param("coupons_id");   #优惠券

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }
        if (empty($coupons_id)) {
            $this->error("请选择优惠券", '', '201');
        }

        #查询是否有交易。有是老人，无是新人
        $order_map['userhome_id'] = $uid;
        $order_map['status'] = array("egt", '2');
        $order_count = $m_order->where($order_map)->count();
        if (!empty($order_count)) {
            $this->error("您已不是新人");
        }

        #判断是否领取
        $if_map['coupons_id'] = $coupons_id;
        $if_map['type'] = '1';
        $if_map['userhome_id'] = $uid;
        $if_data = $m_couponsuser->where($if_map)->find();
        if (!empty($if_data)) {
            $this->error("已领取");
        }

        #优惠券详情
        $coupons_map['id'] = $coupons_id;
        $coupons_data = $m_coupons->where($coupons_map)->find();

        #领取
        $data['userhome_id'] = $uid;
        $data['coupons_id'] = $coupons_id;
        $data['type'] = '1';
        $data['goods_one_type_id'] = $coupons_data['goods_one_type_id'];
        $data['name'] = $coupons_data['name'];
        $data['number'] = $coupons_data['number'];
        $data['money'] = $coupons_data['money'];
        $data['status'] = 0;
        $data['endtime'] = time() + $coupons_data['day'] * 86400;
        $data['createtime'] = time();
        $m_couponsuser->insertGetId($data);

        $this->success("成功");
    }


    /*
    * 我的优惠券
    */
    public function my_coupons()
    {
        $m_couponsuser = Db::name("couponsuser");
        $m_goods_one_type = Db::name("goods_one_type");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $goods_ids = $request->param("goods_ids") ?: '';//判断商品是否适合此购物券

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $end_map['status'] = 0;
        $end_map['userhome_id'] = $uid;
        $end_map['endtime'] = array("elt", time());
        $end_data['status'] = 2;
        $m_couponsuser->where($end_map)->update($end_data);

        $map['userhome_id'] = $uid;
        $map['status'] = array("in", '0,2');
        $where = [];
        if ($goods_ids) {
            $goods_one_type_id = DB::name('goods')->where('id', 'in', $goods_ids)->group('goods_one_type_id')->column('goods_one_type_id');
            $where['goods_one_type_id'] = $goods_one_type_id;
        }
        $list = $m_couponsuser->field("id,goods_one_type_id,name,money,number,endtime,status")->where($map)->order("status asc,id desc")->select();
        foreach ($list as $i => $v) {

            $list[$i]['endtime'] = date("Y-m-d", $list[$i]['endtime']);
            if (!empty($list[$i]['goods_one_type_id'])) {
                $type_map['id'] = $list[$i]['goods_one_type_id'];
                $type_data = $m_goods_one_type->where($type_map)->find();
                $list[$i]['type_name'] = $type_data['name'];
            } else {
                $list[$i]['type_name'] = '全品类';
            }
        }

        $this->success("成功", $list, '200');
    }


    /*
    * 店铺认证
    */
    public function store_approve()
    {
        $m_userstore = Db::name("userstore");
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $name = $request->param("name");   #店主姓名
        $idcard = $request->param("idcard");   #身份证
        $store_name = $request->param("store_name");   #店铺名称
        $mark_group = $request->param("mark_group");   #营销群名
        $image = $request->param("image");   #营业执照

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }
        $renzheng_status = DB::name('userhome')->where('id', $uid)->value('is_renzheng');
        if ($renzheng_status == 3) {
            $this->error("代理商暂不能认证店铺", '', '201');
        }
        if ($renzheng_status == 2) {
            $this->error("请勿重复认证店铺", '', '201');
        }

        #用户资料
        $user_map['id'] = $uid;
        $user_data = $m_userhome->where($user_map)->find();
        #上级资料
        $ppp_map['id'] = $user_data['pid'];
        $ppp_data = $m_userhome->where($ppp_map)->find();

        #判断有没有
        $map['userhome_id'] = $uid;
        $result = $m_userstore->where($map)->find();

        if ($ppp_data['is_renzheng'] == '3') {
            $data['daili_id'] = $user_data['pid'];
        }

        $data['userhome_id'] = $uid;
        $data['name'] = $name;
        $data['idcard'] = $idcard;
        $data['store_name'] = $store_name;
        $data['mark_group'] = $mark_group;
        $data['status'] = '1';
        if (!empty($image)) {
            $data['image'] = trim($image, ',');
        }
        if (empty($result)) {
            #$data['reason'] = '';
            $data['createtime'] = time();
            $m_userstore->insertGetId($data);
        } else {
            #$data['reason'] = '';
            $m_userstore->where($map)->update($data);
        }

        $this->success("成功");
    }

    /*
    * 店铺资料
    */
    public function store_data()
    {
        $m_userstore = Db::name("userstore");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $store_map['userhome_id'] = $uid;
        $store_data = $m_userstore->field("name,idcard,store_name,image,mark_group,reason,status")->where($store_map)->find();
        if (!empty($store_data['image'])) {
            $image_array = explode(',', $store_data['image']);
            $new_login = new Login();
            foreach ($image_array as $i => $v) {
                $image_array[$i] = $new_login->image_url($image_array[$i]);
            }
            $store_data['image_url'] = implode(',', $image_array);
        } else {
            $store_data['image_url'] = '';
        }

        $this->success("成功", $store_data);
    }

    /*
    * 个人资料
    */
    public function my_data()
    {
        $m_userhome = Db::name("userhome");
        $m_userstore = Db::name("userstore");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $user_map['id'] = $uid;
        $user_data = $m_userhome->field("avatar,nickname,birthday,phone,is_renzheng")->where($user_map)->find();
        $user_data['phone_s'] = $user_data['phone'];
        $user_data['phone'] = substr($user_data['phone'], 0, 3) . '****' . substr($user_data['phone'], 7);
        $new_login = new Login();
        $user_data['avatar'] = $new_login->image_url($user_data['avatar']);

        #查询店铺状态
        $store_map['userhome_id'] = $uid;
        $store_data = $m_userstore->where($store_map)->find();
        if (empty($store_data)) {
            $user_data['store_status'] = 0;
        } else {
            $user_data['store_status'] = $store_data['status'];
            $user_data['store_name'] = $store_data['store_name'];
        }

        $this->success('成功', $user_data, 200);
    }

    /*
    * 个人资料
    */
    public function my_invitation_code()
    {
        $m_userhome = Db::name("userhome");
        $m_userstore = Db::name("userstore");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $user_map['id'] = $uid;
        $user_data = $m_userhome->field("invite_image")->where($user_map)->find();

        $new_login = new Login();
        $user_data['invite_image'] = $new_login->image_url($user_data['invite_image']);

        $this->success('成功', $user_data, 200);
    }

    /*
    * 个人中心
    */
    public function my_detail()
    {
        $m_userhome = Db::name("userhome");
        $m_userstore = Db::name("userstore");
        $m_couponsuser = Db::name("couponsuser");
        $m_orderdetail = Db::name("orderdetail");
        $m_order = Db::name("order");
        $m_level = Db::name("level");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $token = $request->param("token") ?: 0;//
        $jm_str = $request->param("jm_str") ?: 0;//
        $res = yanzheng($uid, $token, $jm_str);
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $user_map['id'] = $uid;
        $user_data = $m_userhome->field("avatar,nickname,birthday,phone,is_renzheng,vouchers,bean,use_integral,add_integral,levelId,isVip,vipTime")->where($user_map)->find();
        $user_data['phone_s'] = $user_data['phone'];
        $user_data['phone'] = substr($user_data['phone'], 0, 3) . '****' . substr($user_data['phone'], 7);
        $new_login = new Login();
        $user_data['avatar'] = $new_login->image_url($user_data['avatar']);

        #查询店铺状态
        $store_map['userhome_id'] = $uid;
        $store_data = $m_userstore->where($store_map)->find();
        if (empty($store_data)) {
            $user_data['store_status'] = 0;
        } else {
            $user_data['store_status'] = $store_data['status'];
            $user_data['store_name'] = $store_data['store_name'];
        }

        #查询用户优惠券数量
        $coupons_map['userhome_id'] = $uid;
        $coupons_map['status'] = '0';
        $user_data['coupons_count'] = $m_couponsuser->where($coupons_map)->count();

        #查询订单数量
        $order_map['status'] = '1';
        $order_map['is_integral'] = '0';
        $order_map['userhome_id'] = $uid;
        $user_data['order_count1'] = $m_order->where($order_map)->whereRaw("(select count(*) from yc_orderdetail where yc_orderdetail.order_id = yc_order.id and yc_orderdetail.is_shouhou not in(1,2)) != 0")->count();

        $order_map['status'] = '2';
        $order_map['is_integral'] = '0';
        $user_data['order_count2'] = $m_order->where($order_map)->whereRaw("(select count(*) from yc_orderdetail where yc_orderdetail.order_id = yc_order.id and yc_orderdetail.is_shouhou not in(1,2)) != 0")->count();

        $order_map['status'] = '3';
        $order_map['is_integral'] = '0';
        $user_data['order_count3'] = $m_order->where($order_map)->whereRaw("(select count(*) from yc_orderdetail where yc_orderdetail.order_id = yc_order.id and yc_orderdetail.is_shouhou not in(1,2)) != 0")->count();

//        $order_map['status'] = '4';
//        $user_data['order_count4'] = $m_order->where($order_map)->whereRaw("(select count(*) from yc_orderdetail where yc_orderdetail.order_id = yc_order.id and yc_orderdetail.is_shouhou not in(1,2)) != 0")->count();

        unset($order_map['status']);
        unset($order_map['is_integral']);
        //$order_map['is_shouhou'] = array("in", '1,2,3');
        $order_map['is_shouhou'] = 1;
        $user_data['order_count5'] = $m_orderdetail->where($order_map)->count();
        $level = $m_level->where(['levelId' => $user_data['levelId']])->find();
        $user_data['level_name'] = $level['levelName'];

        $this->success('成功', $user_data, 200);
    }

    /*
    * 我的邀请
    */
    public function my_invite()
    {
        $m_userhome = Db::name("userhome");
        $m_user_relation = Db::name("user_relation");

        $request = Request::instance();
        $pagesize = $request->param("pagesize") ?: 10;
        $uid = $request->param("uid");
        $token = $request->param("token") ?: 0;//
        $jm_str = $request->param("jm_str") ?: 0;//
        $res = yanzheng($uid, $token, $jm_str);
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }
        $user = $m_userhome->where(['id' => $uid])
            ->find();

        $user = DB::name('userhome t1')
            ->leftJoin('user_invite_num t2', 't1.id = t2.userId')
            ->where(['t1.id' => $uid])
            ->field('t1.*,t2.inviteUserNum,t2.indirectInviteUserNum')
            ->find();
        $list = DB::name('userhome t1')
            ->leftJoin('user_invite_num t2', 't1.id = t2.userId')
            ->leftJoin('level t3', 't1.levelId = t3.levelId')
            ->where(['t2.inviteUserId' => $user['id']])
            ->field('t1.*,t2.inviteUserNum,t2.indirectInviteUserNum,t3.levelName')
            ->order('t1.id', 'desc')
            ->paginate($pagesize);
        $user['inviteUserList'] = $list->items();
        $user['totalNum'] = $list->total();
        $loginService = new Login();
        $user['avatar'] = $loginService->image_url($user['avatar']);
        $user['invite_image'] = $loginService->image_url($user['invite_image']);
        foreach ($user['inviteUserList'] as $key => $value) {
            $user['inviteUserList'][$key]['avatar'] = $loginService->image_url($value['avatar']);
        }
        $this->success('成功', $user, 200);
    }

    /*
    * 我的积分记录
    */
    public function my_score()
    {
        $m_userhome = Db::name("userhome");
        $m_user_income_score_log = Db::name("user_income_score_log");

        $request = Request::instance();
        $pagesize = $request->param("pagesize") ?: 10;
        $status = $request->param("status");
        $uid = $request->param("uid");
        $token = $request->param("token") ?: 0;//
        $jm_str = $request->param("jm_str") ?: 0;//
        $res = yanzheng($uid, $token, $jm_str);
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }
        $sql = $m_user_income_score_log->where(['userId' => $uid]);
        if (isset($status) && !empty($status)) {
            if ($status == "ENTER") {
                $sql->whereIn('source', ['SHOP', 'SHARE', 'SALE', 'INTEREST', 'SIGN','GAMBLEGET'])
                    ->whereRaw("status != 'WAIT'");
            }
            if ($status == "WAIT") {
                $sql->where('status', $status);
            }
            if ($status == "CONSUME") {
                $sql->whereIn('source', ['LONGTIME', 'CONSUME', 'CONPOUT','GAMBLE'])
                    ->whereRaw("status != 'WAIT'");
            }
        }
        $list = $sql->order('createTime', 'desc')->order('incomeScoreLogId', 'desc')
            ->paginate($pagesize);
        $data['incomeScoreLogList'] = $list->items();
        $data['totalNum'] = $list->total();

        $this->success('成功', $data, 200);
    }

    /*
    * 编辑个人资料
    */
    public function edit_mydata()
    {
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $avatar = $request->param("avatar");
        $nickname = $request->param("nickname");
        $birthday = $request->param("birthday");

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        if (!empty($avatar)) {
            $data['avatar'] = $avatar;
        }
        if (!empty($nickname)) {
            $data['nickname'] = $nickname;
        }
        if (!empty($birthday)) {
            $data['birthday'] = $birthday;
        }

        if (!empty($data)) {
            $map['id'] = $uid;
            $m_userhome->where($map)->update($data);
        }
        #设置属性  头像、昵称
        require_once "./huanxin/Easemob.class.php";
        $e = new \Easemob();
        $avatar = path($avatar);
        $e->editUser($uid, $nickname, $avatar);
        $this->success("成功");
    }


    /*
    * 系统通知
    */
    public function message()
    {
        $m_message = Db::name("message");
        $m_messageuser = Db::name("messageuser");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        // if ($res == 0) {
        //     $this->error('账号异常','',206);
        // }
        // if ($res == 1) {
        //     $this->error('非法的请求','',201);
        // }
        $page = $request->param("page") ? $request->param("page") : 1;
        $page_count = $request->param("page_count") ? $request->param("page_count") : 10;

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $map['yc_messageuser.userhome_id'] = $uid;
        // $map['yc_message.type'] = 2;
        // $mapor['yc_message.type'] = 1;
        $list = $m_message
            ->join("yc_messageuser", 'yc_message.id = yc_messageuser.message_id', 'left')
            ->field("yc_message.name,yc_message.id,yc_messageuser.createtime,yc_message.createtime as time")
            ->where($map)
            // ->whereor($mapor)
            ->page($page, $page_count)
            ->order("yc_message.id desc")
            ->select();
        //$list = $m_message->query("SELECT `yc_message`.`name`,`yc_message`.`id`,`yc_messageuser`.`createtime` FROM `yc_message` left JOIN `yc_messageuser` ON `yc_message`.`id`=`yc_messageuser`.`message_id` WHERE (`yc_message`.`type` = 2 AND `yc_messageuser`.`userhome_id` = '3') OR `yc_message`.`type` = 1 ORDER BY `yc_message`.`id` DESC LIMIT 0,10");
        /*echo $m_message->getLastSql();
        dump($list);die;*/
        foreach ($list as $i => $v) {
            if (!empty($list[$i]['time'])) {
                $list[$i]['createtime'] = $list[$i]['time'];
            }
            $list[$i]['createtime'] = date("Y-m-d H:i", $list[$i]['createtime']);
            unset($list[$i]['time']);
        }

        $this->success("成功", $list);
    }

    /*
    * 系统通知详情
    */
    public function message_data()
    {
        $m_message = Db::name("message");

        $request = Request::instance();
        $id = $request->param("id");
        // $res = yanzheng($uid,$this->request->param("token"),$this->request->param("jm_str"));
        // if ($res == 0) {
        //     $this->error('账号异常','',206);
        // }
        // if ($res == 1) {
        //     $this->error('非法的请求','',201);
        // }

        if (empty($id)) {
            $this->error("请选择通知");
        }

        $map['id'] = $id;
        $data = $m_message->field("content")->where($map)->find();

        $this->success("成功", $data['content']);
    }

    /*
    * 物流信息
    */
    public function logistics()
    {
        $m_logistics = Db::name("logistics");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $page = $request->param("page") ? $request->param("page") : 1;
        $page_count = $request->param("page_count") ? $request->param("page_count") : 10;

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }

        $map['userhome_id'] = $uid;
        $list = $m_logistics->field("name,order_id,createtime")->where($map)->order("id desc")->select();
        foreach ($list as $i => $v) {
            $list[$i]['createtime'] = date("Y-m-d H:i", $list[$i]['createtime']);
        }

        $this->success("成功", $list);
    }


    /*
    * 优惠活动列表
    */
    public function discounts()
    {
        $m_reduced = Db::name("reduced");

        $request = Request::instance();
        $page = $request->param("page") ? $request->param("page") : 1;
        $page_count = $request->param("page_count") ? $request->param("page_count") : 10;

        $list = $m_reduced->field("id,name,image,type,goods_id,createtime")->order("id desc")->select();
        $new_login = new Login();
        foreach ($list as $i => $v) {
            $list[$i]['image'] = $new_login->image_url($list[$i]['image']);
            $list[$i]['createtime'] = date("Y-m-d H:i", $list[$i]['createtime']);
        }
        $this->success("成功", $list);
    }

    /*
    * 查询活动详情
    */
    public function discounts_data()
    {
        $m_reduced = Db::name("reduced");

        $request = Request::instance();
        $id = $request->param("id");


        $map['id'] = $id;
        $data = $m_reduced->field("content")->where($map)->find();

        $this->success("成功", $data);
    }

    /*
    * 消息中心
    */
    public function message_centre()
    {
        $m_message = Db::name("message");
        $m_messageuser = Db::name("messageuser");
        $m_logistics = Db::name("logistics");
        $m_reduced = Db::name("reduced");

        $request = Request::instance();
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        // if ($res == 0) {
        //     $this->error('账号异常','',206);
        // }
        // if ($res == 1) {
        //     $this->error('非法的请求','',201);
        // }

        if (empty($uid)) {
            $this->error("请登录", '', '201');
        }
        //判断是否有系统消息
        $mess = DB::name('message')->where('type', 1)->order('id desc')->limit(0, 5)->select();
        $u_message = DB::name('messageuser');
        if ($mess) {
            // code...
            foreach ($mess as $key => $value) {
                $is_cz = $u_message->where('userhome_id', $uid)->where('message_id', $value['id'])->find();
                if (!$is_cz) {
                    $u_message->insert(['userhome_id' => $uid, 'message_id' => $value['id'], 'createtime' => $value['createtime'], 'is_read' => 0]);
                }
            }
        }


        $map1['yc_messageuser.userhome_id'] = $uid;
        // $map1['yc_message.type'] = 2;
        $mapor1['yc_message.type'] = 1;
        $data1 = $m_message
            ->join("yc_messageuser", 'yc_message.id = yc_messageuser.message_id', 'left')
            ->field("yc_message.name,yc_message.id,yc_messageuser.createtime,yc_message.createtime as time,yc_messageuser.is_read,yc_messageuser.userhome_id")
            ->where($map1)
            // ->whereor($mapor1)
            ->order("yc_message.id desc,yc_messageuser.id desc")
            ->find();
        // ->select(false);
        // dump($data1);die;

        $map2['userhome_id'] = $uid;
        $data2 = $m_logistics->field("name,createtime,is_read")->where($map2)->order("id desc")->find();

        $data3 = $m_reduced->field("name,createtime")->order("id desc")->find();
        $data3_read = DB::name('reduced_read')->where('userhome_id', $uid)->value('is_read');
        if ($data3_read == 0 || is_null($data3_read)) {
            $data3_read = 0;
        }
        $echo_data = [];

        if (!empty($data1)) {
            if (!empty($data1['time'])) {
                $data1['createtime'] = $data1['time'];
                unset($data1['time']);
                if ($data1['is_read'] == '') {
                    $data1['is_read'] = 0;
                }
            }
            $data1['createtime'] = date("Y-m-d H:i", $data1['createtime']);
            $echo_data['data1'] = $data1;
        }
        if (!empty($data2)) {
            $data2['createtime'] = date("Y-m-d H:i", $data2['createtime']);
            $echo_data['data2'] = $data2;
        }
        if (!empty($data3)) {
            $new_login = new Login();
            $data3['createtime'] = date("Y-m-d H:i", $data3['createtime']);
            $data3['is_read'] = $data3_read;
            $echo_data['data3'] = $data3;

        }
        if(!isset($echo_data[0])){
            $echo_data = null;
        }

        $this->success("成功", $echo_data);
    }

    //消息未读改成已读
    public function update_read()
    {
        $request = Request::instance();
        $uid = $request->param("uid");
        $type = $request->param("type") ?: 1;//1=系统消息,2=物流消息,3=优惠活动
        if ($type == 1) {
            DB::name('messageuser')->where('userhome_id', $uid)->update(['is_read' => 1]);
            $mess = DB::name('message')->where('type', 1)->order('id desc')->find();
            //查询是否存在系统消息
            // $is_cz = DB::name('messageuser')->where('userhome_id',$uid)->where('message_id',$mess['id'])->find();
            // // dump($is_cz);die;
            // if (!$is_cz) {
            //     // code...
            //     DB::name('messageuser')->insert(['userhome_id'=>$uid,'message_id'=>$mess['id'],'createtime'=>$mess['createtime'],'is_read'=>1]);
            // }
        }
        if ($type == 2) {
            DB::name('logistics')->where('userhome_id', $uid)->update(['is_read' => 1]);
        }
        if ($type == 3) {
            $res = DB::name('reduced_read')->where('userhome_id', $uid)->find();
            if (!$res) {
                DB::name('reduced_read')->insert(['is_read' => 1, 'userhome_id' => $uid]);
            } else {
                DB::name('reduced_read')->where('userhome_id', $uid)->update(['is_read' => 1]);
            }

        }
        $this->success('OK', '', 200);


    }

    //首页 查询是否有未读消息
    public function get_weidu_message()
    {
        $request = Request::instance();
        $uid = $request->param("uid");
        $is_read1 = DB::name('messageuser')->where('userhome_id', $uid)->where('is_read', 0)->find();
        $is_read2 = DB::name('logistics')->where('userhome_id', $uid)->where('is_read', 0)->find();
        $is_read3 = DB::name('reduced_read')->where('userhome_id', $uid)->where('is_read', 0)->find();

        //添加系统消息
        if ($is_read3 || $is_read2 || $is_read1) {
            $this->success('OK', ['is_read' => 0], 200);
        } else {
            $this->success('OK', ['is_read' => 1], 200);
        }

    }

    /**
     * 获取群成员
     * @param $group_id 用户名
     */
    public function group_user_index()
    {
        $request = Request::instance();
        $group_id = $request->param("group_id");

        require_once "./huanxin/Easemob.class.php";
        $e = new \Easemob();
        //传入用户名和登录密码参数注册为IM用户
        $result_u = $e->getGroupUsers($group_id);
        //dump($result_u);die;
        if (empty($result_u['data'])) {
            $this->error("群不存在");
        }
        #群主
        $user_data1 = array_column($result_u['data'], 'owner');
        $user_data1 = $e->getGroupUsersdetail($user_data1);
        $user_data1 = $user_data1['data'];
        foreach ($user_data1 as $i => $v) {
            $user_data1[$i]['id'] = $i;
        }
        $user_data1 = array_merge($user_data1);
        #成员
        $user_data2 = array_column($result_u['data'], 'member');
        $chunk_result = array_chunk($user_data2, 1);

        $user_data2 = array();
        foreach ($chunk_result as $i => $v) {
            $user1 = $e->getGroupUsersdetail($chunk_result[$i]);
            $user1 = $user1['data'];
            foreach ($user1 as $ii => $vv) {
                $user1[$ii]['id'] = $ii;
            }

            $user_data2 = array_merge($user_data2, $user1);
        }

        $echo_data['user_data1'] = $user_data1;
        $echo_data['user_data2'] = $user_data2;

        $this->success("成功", $echo_data);
    }


    /*
    * 添加群成员
    */
    public function group_add_user()
    {
        $m_userhome = Db::name("userhome");

        $request = Request::instance();
        $group_id = $request->param("group_id");
        $phone = $request->param("phone");

        if (empty($phone)) {
            $this->error("手机号不能为空");
        }
        if (empty($group_id)) {
            $this->error("请选择群");
        }

        $map['phone'] = $phone;
        $data = $m_userhome->field("id")->where($map)->find();

        require_once "./huanxin/Easemob.class.php";
        $e = new \Easemob();
        $result_u = $e->addGroupMember($group_id, $data['id']);
        if (!empty($result_u['error'])) {
            $this->error("添加失败");
        }
        $this->success("成功");
    }


    /*
    * 发布群公告
    */
    public function group_notice()
    {
        $m_group_notice = Db::name("group_notice");

        $request = Request::instance();
        $group_number = $request->param("group_id");
        $content = $request->param("content");

        $data['group_number'] = $group_number;
        $data['content'] = $content;
        $data['createtime'] = time();
        $m_group_notice->insertGetId($data);

        $this->success("成功");
    }


    /*
    * 群公告列表
    */
    public function group_notice_list()
    {
        $m_group_notice = Db::name("group_notice");

        $request = Request::instance();
        $group_number = $request->param("group_id");
        $page = $request->param("page") ? $request->param("page") : 1;
        $page_count = $request->param("page_count") ? $request->param("page_count") : 10;

        $map['group_number'] = $group_number;
        $list = $m_group_notice->field("content,createtime")->where($map)->page($page, $page_count)->select();

        foreach ($list as $i => $v) {
            $list[$i]['createtime'] = date("Y-m-d", $list[$i]['createtime']);
        }

        $this->success("成功", $list);
    }


    /*
    * 大转盘设置
    */
    public function luckydrawset()
    {
        $m_luckydrawset = Db::name("luckydrawset");

        $data = $m_luckydrawset->field("number,content")->find();
        $money = DB::name('luckydraw')->where('type', 3)->order('money desc')->value('money');
        $data['money'] = $money;

        $this->success("成功", $data);
    }


    /*
    * 大转盘
    */
    public function luckydraw_list()
    {
        $m_luckydrawdetail = Db::name("luckydrawdetail");
        $m_luckydraw = Db::name("luckydraw");
        $m_luckydrawset = Db::name("luckydrawset");

        $request = Request::instance();
        $uid = $request->param("uid");   #用户id
        $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        #查询当日是否免费抽取
        $today_map['userhome_id'] = $uid;
        $today_map['status'] = 1;
        $today_map['today'] = strtotime(date("Y-m-d", time()));
        $today_data = $m_luckydrawdetail->where($today_map)->find();
        if (!empty($today_data)) {
            $echo_data['if_data'] = 0;
        } else {
            $echo_data['if_data'] = 1;
        }

        $list = $m_luckydraw->field("id,name,type,money,meet,probability,validitytime")->order("sort asc")->select();

        $echo_data['list'] = $list;
        $this->success('成功', $echo_data, 200);
    }


    /*
    * 中奖
    */
    public function winning_data()
    {
        $m_userhome = Db::name("userhome");
        $m_luckydraw = Db::name("luckydraw");
        $m_luckydrawdetail = Db::name("luckydrawdetail");
        $m_luckydrawset = Db::name("luckydrawset");
        $m_bean = Db::name("bean");
        $m_vouchers = Db::name("vouchers");
        $m_couponsuser = Db::name("couponsuser");

        $request = Request::instance();
        $uid = $request->param("uid");   #用户id
        // $uid = $request->param("uid");
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $id = $request->param("id");     #中奖id
        $status = $request->param("status");     #抽奖类型:1=每天一次,2=浏览商品,3=芸豆兑换

        if (empty($uid)) {
            $this->error("请登录");
        }

        #用户信息
        $user_map['id'] = $uid;
        $user_data = $m_userhome->where($user_map)->find();

        #中奖设置
        $setdata = $m_luckydrawset->field("number")->find();

        $map['id'] = $id;
        $data = $m_luckydraw->where($map)->find();

        if (empty($data)) {
            $this->error("抽奖错误");
        }

        if ($status == 1) {
            #查询当日是否免费抽取
            $today_map['userhome_id'] = $uid;
            $today_map['status'] = 1;
            $today_map['today'] = strtotime(date("Y-m-d", time()));
            $today_data = $m_luckydrawdetail->where($today_map)->find();
            if (!empty($today_data)) {
                $this->error("今日已免费抽取");
            }
        } elseif ($status == 3) {
            #一百芸豆兑换的
            if ($user_data['bean'] < $setdata['number']) {
                $this->error("芸豆余额不足");
            }

            #扣除明细
            $m_userhome->where($user_map)->setDec("bean", $setdata['number']);
            $bean_data['userhome_id'] = $uid;
            $bean_data['bean_num'] = $setdata['number'];
            $bean_data['type'] = 5;
            $bean_data['createtime'] = time();
            $bean_data['signnum'] = 0;
            $bean_data['signdate'] = '0000-00-00';
            $m_bean->insertGetId($bean_data);
        } else {
            $this->error("抽奖失败，请重试");
        }

        $detail_data['validity'] = 0;     #有效期
        if ($data['type'] == '1') {
            #谢谢参与
        } elseif ($data['type'] == '2') {
            #抵扣券   余额
            $m_userhome->where($user_map)->setInc("vouchers", $data['money']);
            $vouchers_data['userhome_id'] = $uid;
            $vouchers_data['bean_num'] = $data['money'];
            $vouchers_data['type'] = 9;
            $vouchers_data['user_id'] = 0;
            $vouchers_data['createtime'] = time();
            if ($data['money'] > 0) {
                // code...
                $m_vouchers->insertGetId($vouchers_data);
            }

            $user_update['end_rz_time'] = time();
            $m_userhome->where($user_map)->update($user_update);
        } elseif ($data['type'] == '3') {
            #优惠券   满减
            $couponsuser_data['userhome_id'] = $uid;
            $couponsuser_data['coupons_id'] = 0;
            $couponsuser_data['type'] = 2;
            $couponsuser_data['goods_one_type_id'] = 0;
            $couponsuser_data['name'] = $data['name'];
            $couponsuser_data['money'] = $data['money'];
            $couponsuser_data['number'] = $data['meet'];
            $couponsuser_data['status'] = 0;
            #$couponsuser_data['endtime'] = time() + $data['validity'] * 86400;   #有效期七天（暂时不用）
            $couponsuser_data['endtime'] = time() + 7 * 86400;   #有效期七天
            $couponsuser_data['createtime'] = time();
            $m_couponsuser->insertGetId($couponsuser_data);

            #$detail_data['validity'] = time() + $data['validity'] * 86400;     #有效期（暂时不用）
        }
        #中奖明细
        $detail_data['name'] = $data['name'];
        $detail_data['userhome_id'] = $uid;
        $detail_data['type'] = $data['type'];
        $detail_data['status'] = $status;
        $detail_data['money'] = $data['money'];
        $detail_data['meet'] = $data['meet'];
        $detail_data['today'] = strtotime(date("Y-m-d", time()));
        $detail_data['createtime'] = time();
        $m_luckydrawdetail->insertGetId($detail_data);
        $this->success("成功");
    }

    public function vip_list()
    {
        $levelList = Db::name("level")->order('levelId', "asc")->select();
        $request = Request::instance();
        $uid = $request->param("uid") ? $request->param("uid") : 0;
        $user = Db::name("userhome")->where(['id' => $uid])->lock(true)->find();
        $num = count($levelList);
        $gang = 1;
        foreach ($levelList as $key => $value) {
            $levelList[$key]['status'] = 0;
            $levelList[$key]['difference'] = $value['integral'];
            $levelList[$key]['is_use'] = 0;
            $levelList[$key]['user_integral'] = 0;
            $levelList[$key]['is_gang'] = 0;
            $levelList[$key]['next_integral'] = 0;
            $levelList[$key]['is_yuanlai'] = 1;
            if (($key + 1) < $num) {
                $levelList[$key]['content'] = "距离" . $levelList[$key + 1]['levelName'] . "还需要" . $levelList[$key + 1]['integral'] . "积分";
            } else {
                $levelList[$key]['content'] = "距离" . $value['levelName'] . "还需要" . $value['integral'] . "积分";
            }
            if ($user) {
                if (($key + 1) < $num) {
                    $chaju = ((intval(strval($levelList[$key + 1]['integral'] * 100)) - intval(strval($user['add_integral'] * 100))) / 100);
                    if ($chaju <= 0) {
                        $levelList[$key]['content'] = "您已满足成为" . $levelList[$key + 1]['levelName'] . "所需要的积分";
                    } else {
                        $levelList[$key]['content'] = "距离" . $levelList[$key + 1]['levelName'] . "还需要" . $chaju . "积分";
                    }
                    $levelList[$key]['next_integral'] = $levelList[$key + 1]['integral'];
                    if ($gang == 1) {
                        $levelList[$key]['content'] = "恭喜您已升级为" . $levelList[$key + 1]['levelName'];
                        $levelList[$key]['is_gang'] = 1;
                        $levelList[$key]['is_yuanlai'] = 0;
                    }
                } else {
                    $chaju = ((intval(strval($value['integral'] * 100)) - intval(strval($user['add_integral'] * 100))) / 100);
                    if ($chaju <= 0) {
                        $levelList[$key]['content'] = "您已满足成为" . $value['levelName'] . "所需要的积分";
                    } else {
                        $levelList[$key]['content'] = "距离" . $value['levelName'] . "还需要" . $chaju . "积分";
                    }
                }
                $levelList[$key]['user_integral'] = $user['add_integral'];
                if ($user['levelId'] == $value['levelId']) {
                    if (($key + 1) < $num) {
                        $chaju = ((intval(strval($levelList[$key + 1]['integral'] * 100)) - intval(strval($user['add_integral'] * 100))) / 100);
                        if ($chaju <= 0) {
                            $levelList[$key]['content'] = "您已满足成为" . $levelList[$key + 1]['levelName'] . "所需要的积分";
                        } else {
                            $levelList[$key]['content'] = "距离" . $levelList[$key + 1]['levelName'] . "还需要" . $chaju . "积分";
                        }
                    } else {
                        $levelList[$key]['content'] = "恭喜您已升级为" . $levelList[$key]['levelName'];
                    }
                    $levelList[$key]['is_use'] = 1;
                    $gang = 0;
                }
                if (intval(strval($user['add_integral'] * 100)) >= intval(strval($value['integral'] * 100))) {
                    $levelList[$key]['status'] = 1;
                    $levelList[$key]['difference'] = 0;
                } else {
                    $levelList[$key]['difference'] = (intval(strval($value['integral'] * 100)) - intval(strval($user['add_integral'] * 100))) / 100;
                }
            }
        }
        $this->success('成功', $levelList, 200);
    }

    public function getDistrictProvince()
    {
        $request = Request::instance();
        $district = $request->param("district");
        $sql = Db::name("district");
        if (isset($district) && !empty($district)) {
            $sql->where('district', 'like', "%$district%");
        }
        $provinceDistrictList = $sql->where('level', 1)->field('district_id,district')->select();
        $provinceCityList = $sql->where('level', 2)->field('district_id,district,pid')->select();
        foreach ($provinceDistrictList as $key=>$value){
            $provinceDistrictList[$key]['city'] = [];
            unset($k);
            unset($val);
            foreach ($provinceCityList as $k=>$val){
                if($val['pid'] == $value['district_id']){
                    $provinceDistrictList[$key]['city'][] = $val;
                    unset($provinceCityList[$k]);
                }
            }
        }
        $data = [];
        $arr = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z'];
        unset($key);
        unset($value);
        unset($k);
        unset($v);
        foreach ($arr as $key => $value) {
            $list = [];
            unset($k);
            unset($v);
            foreach ($provinceDistrictList as $k => $v) {
                $chinese = mb_substr($v['district'], 0, 1, 'utf-8');
                $letter = $this->getFirstCharter($chinese);
                if($letter == $value){
                    $list[] = $v;
                    unset($provinceCityList[$k]);
                }
            }
            $data[$key]['initial'] = $value;
            $data[$key]['list'] = $list;
        }
        $districtList = $data;
        $this->success('返回成功', $districtList);
    }

    public function getDistrict()
    {
        $request = Request::instance();
        $district = $request->param("district");
        $isHost = $request->param("isHost");
        $sql = Db::name("district")
            ->where('level', 2);
        if (isset($district) && !empty($district)) {
            $districtList = $sql->where('district', 'like', "%$district%")->field('district_id,district')->select();
        }else{
            if ($isHost) {
                $districtList = $sql->where('isHost', 1)->field('district_id,district')->select();
            } else {
                $districtList = $sql->field('district_id,district')->select();
                $data = [];
                $arr = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z'];
                foreach ($arr as $key => $value) {
                    $list = [];
                    unset($k);
                    unset($v);
                    foreach ($districtList as $k => $v) {
                        $chinese = mb_substr($v['district'], 0, 1, 'utf-8');
                        $letter = $this->getFirstCharter($chinese);
                        if($letter == $value){
                            $list[] = $v;
                            unset($districtList[$k]);
                        }
                    }
                    $data[$key]['initial'] = $value;
                    $data[$key]['list'] = $list;
                }
                $districtList = $data;
            }
        }
        $this->success('成功', $districtList, 200);
    }

    function getFirstCharter($str)
    {
        if (empty($str)) {
            return '';
        }
        $fchar = ord($str[0]);
        if ($fchar >= ord('A') && $fchar <= ord('z')) return strtoupper($str[0]);
        $s1 = iconv('UTF-8', 'gb2312', $str);
        $s2 = iconv('gb2312', 'UTF-8', $s1);
        $s = $s2 == $str ? $s1 : $str;
        $asc = ord($s[0]) * 256 + ord($s[1]) - 65536;
        if ($asc >= -20319 && $asc <= -20284) return 'A';
        if ($asc >= -20283 && $asc <= -19776) return 'B';
        if ($asc >= -19775 && $asc <= -19219) return 'C';
        if ($asc >= -19218 && $asc <= -18711) return 'D';
        if ($asc >= -18710 && $asc <= -18527) return 'E';
        if ($asc >= -18526 && $asc <= -18240) return 'F';
        if ($asc >= -18239 && $asc <= -17923) return 'G';
        if ($asc >= -17922 && $asc <= -17418) return 'H';
        if ($asc >= -17417 && $asc <= -16475) return 'J';
        if ($asc >= -16474 && $asc <= -16213) return 'K';
        if ($asc >= -16212 && $asc <= -15641) return 'L';
        if ($asc >= -15640 && $asc <= -15166) return 'M';
        if ($asc >= -15165 && $asc <= -14923) return 'N';
        if ($asc >= -14922 && $asc <= -14915) return 'O';
        if ($asc >= -14914 && $asc <= -14631) return 'P';
        if ($asc >= -14630 && $asc <= -14150) return 'Q';
        if ($asc >= -14149 && $asc <= -14091) return 'R';
        if ($asc >= -14090 && $asc <= -13319) return 'S';
        if ($asc >= -13318 && $asc <= -12839) return 'T';
        if ($asc >= -12838 && $asc <= -12557) return 'W';
        if ($asc >= -12556 && $asc <= -11848) return 'X';
        if ($asc >= -11847 && $asc <= -11056) return 'Y';
        if ($asc >= -11055 && $asc <= -10247) return 'Z';
        return null;
    }

    public function my_vip()
    {
        $request = Request::instance();
        $uid = $request->param("uid") ? $request->param("uid") : 0;
        $user = Db::name("userhome")->where(['id' => $uid])->field('id,avatar,nickname,isVip,0 as vipDay,vipTime')->find();
        $loginService = new Login();
        $user['avatar'] = $loginService->image_url($user['avatar']);
        if(isset($user)){
            if(isset($user['vipTime'])){
                $user['vipDay'] = intval((strtotime($user['vipTime']) - time())/86400)+1;
                $user['vipTime'] = date("Y-m-d",strtotime($user['vipTime']));
            }
        }
        $vipList = Db::name("vip")->order('sort')->select();
        $data = [];
        $data['user'] = $user;
        $data['vipList'] = $vipList;
        $this->success('成功', $data, 200);
    }

    public function vip_log()
    {

        $request = Request::instance();
        $uid = $request->param("uid") ? $request->param("uid") : 0;
        $pagesize = $request->param("pagesize") ? $request->param("pagesize") : 10;
        $page = $request->param("page") ?: 1;
        $res = yanzheng($uid, $this->request->param("token"), $this->request->param("jm_str"));
        if ($res == 0) {
            $this->error('账号异常', '', 206);
        }
        if ($res == 1) {
            $this->error('非法的请求', '', 201);
        }
        $list = Db::name("vip_log")
            ->where("userId", $uid)
            ->order('createtime', 'desc')
            ->paginate($pagesize);
        $data = [];
        $data['vipLogList'] = $list->items();
        $data['totalNum'] = $list->total();
        $this->success('成功', $data, 200);
    }

    public function relation()
    {
        $relation = Db::name("relation")->find();
        $this->success('成功', $relation, 200);
    }
}
